<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE HTML>
<html>
<head>

<title>My JSP 'result.jsp' starting page</title>

<link href="img/ico.ico" rel="shortcut icon">

<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<script type="text/javascript" src="js/jquery-min.js"></script>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>

<body>
<%@ include file="pagetop/pagetitle.jsp" %>
<div style="padding-left: 15%;">
	<i class="icon-home"></i><a href="index.action">回主页</a>&gt;&gt;&gt;&gt;&gt;<i class="icon-list"></i>您搜索的结果&gt;
	<br/>
</div>
<br/>
<div style="padding-left: 15%;">
	<input id="nowpage" type="hidden" style="display:none"
		value="${nowPage} " />
	<input id="searchQuestion" type="hidden" style="display:none"
		value="${searchQuestion}" />
	<c:if test="${not empty searchQuestion}">
		<span>您输入的关键词为:${searchQuestion}</span>
	</c:if>
	<c:if test="${empty questionsList}">
    	╭(╯^╰)╮暂时还没有相关搜索内容
    </c:if><br/>
	<c:if test="${not empty totalcount}">
		<span style="color: #999">找到相关的结果${totalcount}条,${maxPage}页,搜索共耗时：${time}秒</span>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			</c:if>
</div>
<div style="padding-left: 15%;">
	<c:forEach var="question" items="${questionsList}" varStatus="state">
		<hr style="color: red;" />
		问题题目:${state.count}<a href="oneQuestion.action?questionId=${question.id }">${question.questionname}</a>---${question.user.username}提问
		<br />
		<c:if test="${empty question.answerses}">
			o(╯□╰)o该问题暂时还没人给出答案！
		</c:if>
		<c:forEach var="answer" items="${question.answerses}" varStatus="substate">
			&nbsp;&nbsp;&nbsp;答案${substate.count}<span>${answer.content}</span>----------答案状态：${answer.state}<br/>
		</c:forEach>
	</c:forEach>

	<%---------------------------------------------------- --%>
	<c:if test="${totalcount!=0 }">
		<c:if test="${not empty totalcount}">
			<span style="color: #999999;">找到相关的结果${totalcount}条,${maxPage}页,搜索共耗时：${time}秒</span>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			</c:if>
		<div class="pagination">
			<ul>
				<li><a id="firstpage" rel="0" href="javascript:void(0)">首页</a>
				</li>
				<li><a id="before" href="javascript:void(0)">上一页</a>
				</li>
				<c:forEach var="pagenum" items="${pagenum}">
					<li><a class="pagenum" rel="${pagenum}"
						href="javascript:void(0)">${pagenum}</a></li>
				</c:forEach>
				<li><a id="next" href="javascript:void(0)">下一页</a>
				</li>
				<li><a id="lastpage" rel="${maxPage-1}"
					href="javascript:void(0)">尾页</a>
				</li>
			</ul>
		</div>
	</c:if>
	<c:if test="${totalcount==0 }">

		<div class="alert alert-error">
			<button class="close" data-dismiss="alert">×</button>
			<strong>Warning!</strong> 您要查的不存在，或者说您输入有误！！！！
		</div>

	</c:if>
	</div>
</body>

<script type="text/javascript">
	$(function() {
		$("#before").click(
				function() {
					//alert($("#searchQuestion").val());
					var nowP = parseInt($("#nowpage").val());
					if (nowP == 0) {
						return false;
					}
					nowP = nowP - 1;
					if (nowP < 0) {
						nowP = 0;
					}
					window.location.href = "searchQuestion.action?nowPage="
							+ nowP + "&searchQuestion="
							+ $("#searchQuestion").val();
				});
		$("#next").click(
				function() {
					var nextP = parseInt($("#nowpage").val());
					if (nextP == $("#lastpage").attr("rel")) {
						return false;
					}
					var m = parseInt($("#lastpage").attr("rel"));
					nextP = nextP + 1;
					if (nextP > m) {
						nextP = m;
					}
					window.location.href = "searchQuestion.action?nowPage="
							+ nextP + "&searchQuestion="
							+ $("#searchQuestion").val();
				});

		$(".pagenum").click(
				function() {
					var page = $(this).attr("rel");
					if (parseInt(page) == (parseInt($("#nowpage").val()) + 1)) {
						return false;
					}
					window.location.href = "searchQuestion.action?nowPage="
							+ (parseInt(page) - 1) + "&searchQuestion="
							+ $("#searchQuestion").val();
				});

		$("#firstpage").click(
				function() {
					if (parseInt($("#nowpage").val()) == ($("#firstpage")
							.attr("rel"))) {
						return false;
					}
					window.location.href = "searchQuestion.action?nowPage="
							+ $("#firstpage").attr("rel") + "&searchQuestion="
							+ $("#searchQuestion").val();
					$("#firstpage").parent().addClass("active");
				});
		$("#lastpage").click(
				function() {
					if (parseInt($("#nowpage").val()) == ($("#lastpage")
							.attr("rel"))) {
						return false;
					}
					window.location.href = "searchQuestion.action?nowPage="
							+ $("#lastpage").attr("rel") + "&searchQuestion="
							+ $("#searchQuestion").val();
				});
	});
</script>
</html>
